package com.dxy.hms.socketio;

import java.util.Set;

public interface ISessionService {

    void addSession(ISession session);

    ISession getSessionById(String sessionId);

    void removeSession(String sessionId);

    default void removeSession(ISession session){
        if (session != null){
            removeSession(session.getSessionId());
        }
    }

    void setUserId(String userId, String sessionId);

    void setRoomId(String roomId, String sessionId);

    void setTag(String tag, String sessionId);

    default void sendMessage(ISession session, String event, Object payload) {
        if (session != null){
            session.sendMessage(event, payload);
        }
    }

    default void sendMessage(String sessionId, String event, Object payload){
        ISession session = getSessionById(sessionId);
        sendMessage(session, event, payload);
    }

    void sendMessageByUserId(String userId, String event, Object payload);

    void sendMessageByRoomId(String roomId, String event, Object payload);

    void sendMessageByTag(String tag, String event, Object payload);

    void sendMessageByTags(Set<String> tags, String event, Object payload);
}
